/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved.
 * distributed with this file and available online at
 */
package com.lap.auth.adapter.driven.web.dict;

import com.lap.auth.application.dict.DictTypeAppService;
import com.lap.auth.application.dict.command.CreateDictTypeCmd;
import com.lap.auth.application.dict.command.UpdateDictTypeCmd;
import com.lap.auth.application.dict.dto.DictTypeDto;
import com.lap.auth.application.dict.dto.QueryDictTypePageQuery;
import com.lap.framework.common.dto.page.PageResponse;
import com.lap.watchdog.starter.annotation.RepeatSubmit;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 提供数字字典分类restful接口层:
 *
 * <ol>
 *   <li>业务规则，原则上不做任何业务逻辑处理，仅仅是技术入口
 *   <li>命名规则，语义上明确接口做什么，推荐使用 Restful 命名 + Verb风格方法名（适配Swagger、Spring）:
 *       <ul>
 *         <li>分页使用 getXXXPage
 *         <li>获取单个 getXXById
 *         <li>保存使用 createXX
 *         <li>更新使用 updateXX
 *         <li>删除使用 deleteXX
 *       </ul>
 * </ol>
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
@Tag(name = "数字字典分类管理", description = "提供数字字典分类基本操作，查询等")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/v1/dict-types")
public class DictTypeController {

  private final DictTypeAppService dictTypeAppService;

  @Operation(summary = "获取数字字典分类")
  @GetMapping
  public PageResponse<DictTypeDto> getDictTypePage(QueryDictTypePageQuery query) {
    return dictTypeAppService.queryDictTypesByPage(query);
  }

  @Operation(summary = "添加数字字典分类")
  @RepeatSubmit
  @PostMapping
  public Integer createDictType(@RequestBody @Valid CreateDictTypeCmd cmd) {
    return dictTypeAppService.createDictType(cmd);
  }

  @Operation(summary = "更新数字字典分类")
  @RepeatSubmit
  @PutMapping("{id}")
  public Integer updateDictType(
      @PathVariable Integer id, @RequestBody @Valid UpdateDictTypeCmd cmd) {
    return dictTypeAppService.updateDictType(id, cmd);
  }

  @Operation(summary = "删除数字字典分类")
  @RepeatSubmit
  @DeleteMapping("{id}")
  public Integer deleteDictType(@PathVariable Integer id) {
    return dictTypeAppService.deleteDictType(id);
  }
}
